package com.rowline.admin.module.study.reflect;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ClassName:UseCaseTracker
 * Created by 245167
 * on 2017/10/31  31:05
 * description:
 */
public class UseCaseTracker {

    public static void trackUseCases(List<Integer> useCases, Class<?> cl) {

        /**
         * getDeclaredMethods()方法可以获取相关对象自己声明的相关方法，
         * 而getAnnotation()则可以获取Method对象的指定注解。
         */
        for(Method m : cl.getDeclaredMethods()) {
            UseCase uc = m.getAnnotation(UseCase.class);
            if(uc != null) {
                System.out.println("Found Use Case: " + uc.id() + " " + uc.description());
                // 删除找到对应注解的id
                useCases.remove(new Integer(uc.id()));

            }
        }
        for(int i : useCases) {
            System.out.println("Warning: Missing use case-" + i);
        }
    }
    public static void main(String[] args) {
        List<Integer> useCases = new ArrayList<Integer>();
        Collections.addAll(useCases, 47, 48, 49, 50, 51);
        trackUseCases(useCases, PasswordUtils.class);
        System.out.println("===============");
    }


}
